package com.song.weektest.controller;

import com.song.weektest.domain.R;
import com.song.weektest.domain.WUser;
import com.song.weektest.service.WUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author TonySong
 * @date 2024/5/29 0029
 * @time 16:34
 */
@RestController
@RequestMapping("/person")
public class PersonController {

    @Resource
    private WUserService wUserService;

//    @GetMapping("/")
//    public R getPerson() {
//        System.out.println("test..........");
//        return R.success(this.wUserService.list());
//    }

    @GetMapping("/")
    public R getPerson(@RequestParam(name = "offset", defaultValue = "1") Integer offset,
                        @RequestParam(name = "pageSize", defaultValue = "4") Integer pageSize,
                       @RequestParam(name = "wUser", required = false) WUser wUser) {
        System.out.println("test..........");
        return R.success(this.wUserService.pageList(offset, pageSize, wUser));
    }

    @PostMapping("/")
    public R savePerson(@RequestBody WUser wUser) {
        return R.success(this.wUserService.save(wUser));
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Integer id){
        this.wUserService.removeById(id);
        return R.success(null);
    }

    @PutMapping("/")
    public R updatePerson(@RequestBody WUser wUser) {
        return R.success(this.wUserService.save(wUser));
    }
}
